<?php

class CCrawl2 extends Zend_Db_Table
{

    protected $_name;

    protected $_primary;

    protected $typeTable=null;

    public function _setup()
    {

        $this->_name=R_PRE."crawl_item2";

        $this->_primary="id";

        parent::_setup();

    }
	
	public function getAll($sql){
		
		$db=$this->getAdapter();
		
		$select=$db->select();
		
		$select->from($this->_name,"*");
		
		return $db->fetchAll($sql);
		
	}
	
	public function updateRecord($itemid,$data)
    {
        $db=$this->getAdapter();
        $where = $db->quoteInto('id = ?', $itemid);
        $rows_affected=$db->update($this->_name,$data,$where);
        if($rows_affected!=1)
        {
            return false;
        }else
        {
            return true;
        }
    }
	
	public function getPageCount($pageNum, $start = '')
	{
		
		$sql = 'select count(*) from ' . $this->_name;
		
		$count = $this->getAdapter()->fetchOne($sql);
		
		return ceil($count / $pageNum);
		
	}
	
	public function getAllCrawls($page, $pageNum)
	{
		$sql = 'select * from ' . $this->_name;
		
		$offset = ($page - 1) * $pageNum;
		
		$sql .= ' order by id asc limit ' . $offset . ',' . $pageNum;
	
		return  $this->getAdapter()->fetchAll($sql);
	}
	
	public function update($sql){
		$db=$this->getAdapter();
		$db->query($sql);
	}
	
	public function getCrawlItem($id){
		$db=$this->getAdapter();
		$crawlItem=$db->fetchAll("SELECT * from ".$this->_name." WHERE id=$id");		
		return $crawlItem[0];
	}
	
	public function getCrawlItems($idArray){
		$idStr = implode(",",$idArray);
		$db=$this->getAdapter();
		$crawlItemArray=$db->fetchAll("SELECT * from ".$this->_name." WHERE id IN ($idStr)");		
		return $crawlItemArray;
	}
	

	
}